package com.shr.exam.netease;

import java.util.Scanner;

public class Main2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int numNode = sc.nextInt();
		int numStep = sc.nextInt();
		int [] parent = new int[numNode];
		for(int i=0;i<numNode-1;i++) 
			parent[i+1] = sc.nextInt();
		int maxVal = 0;
		for(int i=1;i<numNode-1;i++){
			int count =0;
			int cur = i;
			while(true){
				cur = parent[cur];
				count++;
				if(count >= numStep || cur-- == 0) 
					break;
			}
			if(maxVal<count) 
				maxVal = count;
		}
		System.out.println(maxVal+1);
		sc.close();

	}
}
